package com.mmall.other.example.jvm;

import java.io.IOException;

/**
 * @ClassName OutOfMemoryExample1
 * @Describe :
 * @Author : wangfei
 * @Date :  2019/10/23 16:38
 */
public class OutOfMemoryExample1 {

	public static void main(String[] args) throws IOException {
		try {
			gcTest();
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println("has exited gcTest!");
		System.in.read();
		System.in.read();
		System.out.println("out begin gc!");
		for (int i = 0; i < 100; i++) {
			System.gc();
			System.in.read();
			System.in.read();
		}
	}

	private static class Person {
		byte[] data = new byte[20000000];

		Person person = null;

		public void setPerson(Person person) {
			this.person = person;
		}
	}

	private static void gcTest() throws IOException {
		System.in.read();
		System.in.read();
		Person p1 = new Person();
		System.in.read();
		System.in.read();
		Person p2 = new Person();
		p1.setPerson(p2);
		p2.setPerson(p1);
		System.out.println("before exit gctest!");
		System.in.read();
		System.in.read();
		System.gc();
		System.out.println("exit gctest!");
	}
}
